`return value' from Constructor Exception in Java?

Posted by Lajos Nagy on Stack Overflow See other posts from Stack Overflow or by Lajos Nagy
Published on 2010-03-19T00:26:04Z Indexed on 2010/03/19 0:31 UTC
Read the original article Hit count: 251

Filed under:

Take a look that the following code snippet:

A a = null
try {
  a = new A();
} finally {
  a.foo();  // What happens at this point?
}

Suppose A's constructor throws a runtime exception. At the marked line, am I always guaranteed to get a NullPointerException, or foo() will get invoked on a half constructed instance?

© Stack Overflow or respective owner

Related posts about java